var localStore = {
	USER: "_uInfo", //用户信息key
	CP: "_cp", //企业信息
	LIMIT: "_limit", //权限
	DRAFT: "_draft", //产品草稿
	PROJECT: "_project", //服务草稿
	PAY: "_pay", //收款方式
	PAYMENT: "_payment", //付款方式
	LOGIN: "_login",
	TAB_BAR:"_tabbar",//记录当在哪个页面，刷新窗口时用到
	CARD_INFO:"_cardinfo"
}

localStore.setLogin = async function (data) {
	try {
		await uni.setStorage({
			key: this.LOGIN,
			data: data
		});
	} catch (e) {

	}
}

localStore.getLogin = function () {
	let login = uni.getStorageSync(this.LOGIN);
	return login;
}
localStore.getLogin = function () {
	let login = uni.getStorageSync(this.LOGIN);
	return login;
}
localStore.getCard = function () {
	let card = uni.getStorageSync(this.CARD_INFO);
	return card;
}
/****设置编辑卡信息****/
localStore.setCardInfo = async function (data) {
	try {
		await uni.setStorage({
			key: this.CARD_INFO,
			data: data
		});
	} catch (e) {

	}
}

/****设置用户信息****/
localStore.setUserInfo = async function (data) {
	try {
		await uni.setStorage({
			key: this.USER,
			data: data
		});
	} catch (e) {

	}
}

/***获取用户信息***/
localStore.getUserInfo = function () {
	let userInfo = uni.getStorageSync(this.USER);
	return userInfo;
}

/****清除缓存****/
localStore.clearStorage = function () {
	uni.showModal({
		title: '提示',
		content: '确定清除缓存吗?',
		confirmText: '立即清除',
		success(res) {
			if (res.confirm) {
				uni.clearStorageSync();
				uni.showToast({
					title: '清除成功'
				})
			}
		}
	});
}

/****设置企业信息***/
localStore.setCpInfo = async function (data) {
	try {
		await uni.setStorage({
			key: this.CP,
			data: data
		});
	} catch (e) {

	}
}

/*****权限保存*****/
localStore.saveLimit = async function (data) {
	try {
		await uni.setStorage({
			key: this.LIMIT,
			data: data,
			success(res) {
				console.log("权限保存成功！！！", res);
			},
			fail(res) {
				console.log("权限缓存失败！", res);
			},
		});
	} catch (e) {
		console.log("权限缓存失败！！", e);
	}
}

/*****获取本地保存*****/
localStore.getLimits = function (data) {
	let list = uni.getStorageSync(this.LIMIT);
	return list;
}

/****获取企业信息***/
localStore.getCpInfo = function () {
	let cp = uni.getStorageSync(this.CP);
	return cp;
}

/*****保存产品草稿******/
localStore.setGoodsDraft = async function (data, type) {
	try {
		console.log("产品本地保存成功");
		await uni.setStorage({
			key: type == 1 ? this.DRAFT : this.PROJECT,
			data: data,
			success(res) {
				console.log("产品本地保存成功！！！", res);
			},
			fail(res) {
				console.log("产品缓存失败！", res);
			},
		});
	} catch (e) {
		console.log("产品缓存失败！！", e);
	}
}

/******获取产品草稿********/
localStore.getGoodsDraft = function (type) {
	let draft = uni.getStorageSync(type == 1 ? this.DRAFT : this.PROJECT);
	return draft;
}

/****清除产品缓存****/
localStore.removeGoodsDraft = async function () {
	let that = this;
	await uni.removeStorage({
		key: that.DRAFT,
		success(res) {
			console.log("清除草稿缓存成！！！", res);
		}
	})
}
/****清除服务缓存****/
localStore.removeGoodsDraftAll = async function () {
	let that = this;
	await uni.removeStorage({
		key: that.PROJECT,
		success(res) {
			console.log("清除草稿缓存成！！！", res);
		}
	})
}
/***保存用户销售收款方式****/
localStore.savePayType = async function (data) {
	await uni.setStorage({
		key: this.PAY,
		data: data,
		success(res) {
			console.log("支付方式本地保存成功！！！", res);
		},
		fail(res) {
			console.log("支付方式缓存失败！", res);
		},
	});
}

/****获取销售支付方式***/
localStore.getPayType = async function () {
	let pay = await uni.getStorageSync(this.PAY);
	return pay;
}

/***保存用户销售收款方式****/
localStore.savePaymentType = async function (data) {
	await uni.setStorage({
		key: this.PAYMENT,
		data: data,
		success(res) {
			console.log("付款方式本地保存成功！！！", res);
		},
		fail(res) {
			console.log("付款方式缓存失败！", res);
		},
	});
}

/****获取采购付款方式***/
localStore.getPaymentType = function () {
	let payment = uni.getStorageSync(this.PAYMENT);
	return payment;
}

localStore.setTabBarIds = async function(data)
{
	await uni.setStorage({
		key: this.TAB_BAR,
		data: data,
		success(res) {
			console.log("保存成功！！！", res);
		},
		fail(res) {
			console.log("缓存失败！", res);
		},
	});
}

localStore.getTabBarIds = function () {
	let ids = uni.getStorageSync(this.TAB_BAR);
	return ids;
}

export default localStore;